import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/recommend"
  },
  {
    path:"/userinfo",
    name:"userInfo",
    component:()=>import("../views/userinfo.vue"),
    beforeEnter:(to,from,next)=>{
      let login = window.localStorage.getItem("token");
      // 判断没有值
      if(!login){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../components/base/login.vue")
  },
  {
    path:"/recommend",
    name:"recommend",
    component:recommend
  },
  {
    path:"/signin",
    name:"Signin",
    component:()=>import("../views/Signin.vue")
  },
  {
    path:"/singer",
    name:"singer",
    component:()=>import("../views/singer.vue")
  },
  {
    path:"/rank",
    name:"rank",
    component:()=>import("../views/rank.vue")
  },
  {
    path:"/rank/ranklist",
    name:"ranklist",
    component:()=>import("../components/rank/ranklist.vue")
  },
  {
    path:"/rank/singerdetails/:id",
    name:"SingerDetails",
    props:true,
    component:()=>import("../components/rank/SingerDetails.vue")
  },
  {
    path:"/rank/singeralbum/:id",
    name:"SingerAlbum",
    props:true,
    component:()=>import("../components/rank/SingerAlbum.vue")
  },
  {
    path:"/userfollow",
    name:"userfollow",
    props:true,
    component:()=>import("../views/userfollow.vue")
  },
  {
    path:"/userCollection",
    name:"userCollection",
    component:()=>import("../views/userCollection.vue")
  },
  {
    path:"/playback/:id",
    name:"PlayBack",
    component:()=>import("../views/Playback.vue")
  },
  {
    path:"/usercomment",
    name:"usercomment",
    component:()=>import("../views/usercomment.vue")
  },
  {
    path:"/lovemusic",
    name:"lovemusic",
    component:()=>import("../views/lovemusic.vue")
  },
  
  

]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 全局路由守卫
// router.beforeEach((to,from,next)=>{
//   let login = window.localStorage.getItem("token");
//   // 登陆界面
//   if(to.path == "/login"){
//     next();
//     return;
//   }else{
//     // 判断是否登陆
//     if(!login){
//       next('/login');
//       return;
//     }else{
//       next();
//     }
//   }
// })

export default router
